﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace UI
{
    public partial class FrmTXTDisplay : Form
    {
        System.Diagnostics.Process simulation=null;

        
        public FrmTXTDisplay(string Text, System.Diagnostics.Process Simulation)
        {
            
            InitializeComponent();
            this.Text = Text;

            if (Simulation != null)
            {
                simulation = Simulation;
                simulation.OutputDataReceived += new System.Diagnostics.DataReceivedEventHandler(SortOutputHandler);
            }
              
        }
        void SortOutputHandler(object sender, System.Diagnostics.DataReceivedEventArgs e)
        {
            try
            {
                System.Diagnostics.Trace.WriteLine(e.Data);
                this.BeginInvoke(new MethodInvoker(() =>
                 {
                     this.AppendText(e.Data ?? string.Empty);
                 }));
            }
            catch
            { 
            
            }
        }
        void AppendText(string text)
        {
            richTextBox1.AppendText(text +"\n");
            richTextBox1.SelectionStart = richTextBox1.Text.Length;
            richTextBox1.ScrollToCaret();

            
        }
        public void Append(object msg, EventArgs e)
        {
            while (true)
            {
                try
                {

                    this.Invoke((Action)(() => AppendText(msg.ToString())));
                    return;
                }
                catch
                {

                }
            }
            
        }
         

        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {
             
        }
    }
}
